﻿using System;
using System.Collections.Generic;
using System.Resources;
using CuteSprite.Eme.Server.Configuration.Localization.Internal;
using HmFramework.Localization;
using HmFramework.Localization.Internal;

namespace CuteSprite.Eme.Server.Configuration
{
	#region -- EmeConfigStringId --

	internal enum EmeConfigStringId
	{
		FrmMain_Caption_From,
		FrmMain_Caption_tbIPAllow,
		FrmMain_Caption_tbUsers,
		FrmMain_Caption_tbConn,
		FrmMain_Caption_tbSettings,
		FrmMain_Caption_lvwIPColumnStartIP,
		FrmMain_Caption_lvwIPColumnEndIP,
		FrmMain_Caption_lvwIPColumnUser,
		FrmMain_Caption_lvwConnColumnName,
		FrmMain_Caption_lvwConnColumnType,
		FrmMain_Caption_lvwConnColumnDefault,
		FrmMain_Caption_lblDataPath,
		FrmMain_Caption_lblMailPath,
		FrmMain_Caption_lblImPath,
		FrmMain_Caption_lblAttachPath,
		FrmMain_Caption_lblPort,
		Message_DelLocalIP,
		Message_EditLocalIP,
		Message_DelIPConfirm,
		Message_DelAdmin,
		Message_DelUserConfirm,
		FrmIPAccess_Caption_From,
		FrmIPAccess_Caption_gpIPRange,
		FrmIPAccess_Caption_lblStartIP,
		FrmIPAccess_Caption_lblEndIP,
		Message_InvalidStartIP,
		Message_InvalidEndIP,
		FrmUser_Caption_From,
		FrmUser_Caption_gpUser,
		FrmUser_Caption_lblUser,
		FrmUser_Caption_lblPwd,
		Message_UserEmpty,
		Message_UserExists,
		Message_PwdEmpty,
	}

	#endregion

	#region -- EmeConfigLocalizer --

	internal class EmeConfigLocalizer : EmeConfigLocalizerBase<EmeConfigStringId>
	{
		static EmeConfigLocalizer()
		{
			SetActiveLocalizerProvider(new DefaultActiveLocalizerProvider<EmeConfigStringId>(CreateDefaultLocalizer()));
		}

		#region - PopulateStringTable -

		protected override void PopulateStringTable()
		{
			AddString(EmeConfigStringId.FrmMain_Caption_From, "CuteSprite MIS Server Administration Access Configurator");
			AddString(EmeConfigStringId.FrmMain_Caption_tbIPAllow, "IP Allow");
			AddString(EmeConfigStringId.FrmMain_Caption_tbUsers, "Users");
			AddString(EmeConfigStringId.FrmMain_Caption_tbConn, "Connections");
			AddString(EmeConfigStringId.FrmMain_Caption_tbSettings, "Settings");
			AddString(EmeConfigStringId.FrmMain_Caption_lvwIPColumnStartIP, "Start IP");
			AddString(EmeConfigStringId.FrmMain_Caption_lvwIPColumnEndIP, "End IP");
			AddString(EmeConfigStringId.FrmMain_Caption_lvwIPColumnUser, "User Name");
			AddString(EmeConfigStringId.FrmMain_Caption_lvwConnColumnName, "Name");
			AddString(EmeConfigStringId.FrmMain_Caption_lvwConnColumnType, "Type");
			AddString(EmeConfigStringId.FrmMain_Caption_lvwConnColumnDefault, "Default");
			AddString(EmeConfigStringId.FrmMain_Caption_lblDataPath, "Data Storage Path:");
			AddString(EmeConfigStringId.FrmMain_Caption_lblMailPath, "Mail Storage Path:");
			AddString(EmeConfigStringId.FrmMain_Caption_lblImPath, "IM Storage Path:");
			AddString(EmeConfigStringId.FrmMain_Caption_lblAttachPath, "Attachment Storage path:");
			AddString(EmeConfigStringId.FrmMain_Caption_lblPort, "Management Server Port:");

			AddString(EmeConfigStringId.Message_DelLocalIP, "IP range 127.0.0.1 - 127.0.0.1 is permanent system entry and cannot be deleted !");
			AddString(EmeConfigStringId.Message_EditLocalIP, "IP range 127.0.0.1 - 127.0.0.1 is permanent system entry and cannot be modified !");
			AddString(EmeConfigStringId.Message_DelIPConfirm, "Are you sure you want to delete entry '{0}' !");
			AddString(EmeConfigStringId.Message_DelAdmin, "User Administrator is permanent user and cannot be deleted !");
			AddString(EmeConfigStringId.Message_DelUserConfirm, "Are you sure you want to delete user '{0}' !");

			AddString(EmeConfigStringId.FrmIPAccess_Caption_From, "IP Access Settings");
			AddString(EmeConfigStringId.FrmIPAccess_Caption_gpIPRange, "IP Range");
			AddString(EmeConfigStringId.FrmIPAccess_Caption_lblStartIP, "Start IP:");
			AddString(EmeConfigStringId.FrmIPAccess_Caption_lblEndIP, "End IP:");
			AddString(EmeConfigStringId.Message_InvalidStartIP, "Invalid start IP value !");
			AddString(EmeConfigStringId.Message_InvalidEndIP, "Invalid end IP value !");

			AddString(EmeConfigStringId.FrmUser_Caption_From, "User Settings");
			AddString(EmeConfigStringId.FrmUser_Caption_gpUser, "User Info");
			AddString(EmeConfigStringId.FrmUser_Caption_lblUser, "User Name:");
			AddString(EmeConfigStringId.FrmUser_Caption_lblPwd, "Password:");
			AddString(EmeConfigStringId.Message_UserEmpty, "User name cannot be empty !");
			AddString(EmeConfigStringId.Message_UserExists, "Specified user '{0}' already exists !");
			AddString(EmeConfigStringId.Message_PwdEmpty, "User password cannot be empty !");
		}

		#endregion

		public static HmLocalizer<EmeConfigStringId> CreateDefaultLocalizer()
		{
			return new EmeConfigResLocalizer();
		}

		public static String GetString(EmeConfigStringId id)
		{
			return Active.GetLocalizedString(id);
		}

		public static String GetString(String id)
		{
			return GetString((EmeConfigStringId)Enum.Parse(typeof(EmeConfigStringId), id, true));
		}

		public override HmLocalizer<EmeConfigStringId> CreateResXLocalizer()
		{
			return new EmeConfigResLocalizer();
		}
	}

	#endregion

	#region -- EmeConfigResLocalizer --

	internal class EmeConfigResLocalizer : HmResXLocalizer<EmeConfigStringId>
	{
		public EmeConfigResLocalizer()
			: base(new EmeConfigLocalizer())
		{
		}

		protected override ResourceManager CreateResourceManagerCore()
		{
			return new ResourceManager(typeof(EmeConfigResLocalizer).Namespace + ".LocalizationRes", typeof(EmeConfigResLocalizer).Assembly);
		}
	}

	#endregion
}

namespace CuteSprite.Eme.Server.Configuration.Localization.Internal
{
	internal abstract class EmeConfigLocalizerBase<T> : HmLocalizer<T> where T : struct
	{
		protected override void AddString(T id, String str)
		{
			Dictionary<T, String> table = HmLocalizierHelper<T>.GetStringTable(this);
			table[id] = str;
		}
	}
}